package com.yfq;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

/**
 * @author: yfq
 * @date: 2023/2/2 9:14
 * @description:
 */
public class UserServiceMethodInterceptor implements MethodInterceptor {
    @Override
    public Object invoke(MethodInvocation invocation) throws Throwable {
        long start = System.currentTimeMillis();
        try {
            //执行目标方法
            return invocation.proceed();
        } finally {
            //方法返回之前打印监控信息
            System.out.println("监控 - Begin By AOP");
            System.out.println("方法名称：" + invocation.getMethod().getName());
            System.out.println("方法耗时：" + (System.currentTimeMillis() - start) + "ms");
            System.out.println("监控 - End\r\n");
        }
    }
}
